package com.bulk.threadPool;

import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * 自定义拒绝策略
 *
 * @author 散装java
 */

public class TaskRejectedHandler implements RejectedExecutionHandler {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        System.out.println("线程池已满");
        if (!executor.isShutdown()) {
            Runnable poll = executor.getQueue().poll();
            executor.execute(poll);
            executor.getQueue().offer(r);
        }
    }
}
